<!DOCTYPE html>
<html>

<head>
  <script src="../node_modules/angular/angular.js"></script>
  <script src="../node_modules/angular-resource/angular-resource.js"></script>
</head>

<body ng-app="demo">
  <div ng-controller="DemoController">
    <button ng-click="queryResult()">获取</button>
    <button ng-click="saveResult()">保存</button>
    <p>结果：{{ result }}</p>
  </div>
  <script>
    const demo = angular.module('demo', ['ngResource']) // 引入模块
    demo.controller('DemoController', function ($scope, $resource) {
      $scope.result = '...'

      const result = $resource('./result.json', { name: 'zgl' })

      $scope.queryResult = () => {
        // result.get().$promise.then(res => {
        //   console.log(res.data)
        //   $scope.result = res.data
        // })
        result.query(function (res) {
          console.log(res)
        })
      }

      $scope.saveResult = () => {
        result.save(function (res) {
          console.log(res)
        })
      }
    });

    // {
    //   'get': { method: 'GET' },
    //   'save': { method: 'POST' },
    //   'query': { method: 'GET', isArray: true },
    //   'remove': { method: 'DELETE' },
    //   'delete': { method: 'DELETE' }
    // }
  </script>
</body>

</html>